package com.zhyl.demo.service.impl;

import com.zhyl.demo.entity.Patient;
import com.zhyl.demo.mapper.PatientMapper;
import com.zhyl.demo.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class PatientServiceImpl implements PatientService {

    @Autowired
    PatientMapper patientMapper;



    @Override
    public Boolean CreatePatient(Integer pid) {

        Patient patient = new Patient();
        patient.setPatid(pid);
        Integer register = patientMapper.CreatePatient(patient.getPatid());
        if (register>0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Patient showInfo(Integer patid) {
        Patient patient = patientMapper.showInfo(patid);
        if (patient!=null){
            return patient;
        }else {
            return null;
        }

    }

    @Override
    public Boolean updateInfo(Patient patient) {
        Integer res = patientMapper.updateInfo(patient);
        if (res >0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public ArrayList<Patient> searchInfo(String patientName) {
        ArrayList<Patient> patients = patientMapper.searchInfo(patientName);
        if (patients!=null){
            return patients;
        }else {
            return null;
        }
    }

    @Override
    public ArrayList<Patient> getAllPatient() {
        ArrayList<Patient> allPatient = patientMapper.getAllPatient();
        return allPatient;
    }

    @Override
    public Boolean addBalance(Patient patient) {
        Integer i = patientMapper.updateInfo(patient);
        if (i>0){
            return true;
        }else {
            return false;
        }
    }


}
